package com.bye.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.bye.mapper.OrderMapper;
import com.bye.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

@Service
public class OrderServiceImpl implements OrderService {
    @Autowired
    private OrderMapper orderMapper;


    @Override
    public String countAmount() {
        QueryWrapper qr = new QueryWrapper();
        qr.eq("order_status", "已支付");
        qr.select("SUM(actual_payment_amount)");
        List list = orderMapper.selectObjs(qr);
        if (CollectionUtils.isNotEmpty(list) && list.get(0) != null) {
            return (list.get(0).toString());
        }
        return "0";
    }

    @Override
    public String countOrders(){
        QueryWrapper qr = new QueryWrapper();
        qr.eq("order_status", "已支付");
        Long l = orderMapper.selectCount(qr);
        String result = l.toString();
        return result;
    }

}
